#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2024/11/19 15:20
# @Author : XXX
# @Site : 
# @File : save_mode_return.py
# @Software: PyCharm
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2024/11/19 11:35
# @Author : XXX
# @Site :
# @File : test_action.py
# @Software: PyCharm
import os, pickle

from all_config import dryFan_action_space, cduValve1_action_space
from util.action_caiji_class import action_caiji


file_name = 'action_config.pkl'

# 尝试删除文件
try:
    os.remove(file_name)
    print(f"文件 '{file_name}' 已成功删除。")
except FileNotFoundError:
    print(f"文件 '{file_name}' 不存在。")
except PermissionError:
    print(f"没有权限删除文件 '{file_name}'。")
except Exception as e:
    print(f"删除文件时发生错误: {e}")




action_caiji_each = action_caiji(dryFan_action_space, cduValve1_action_space)
#初始化动作配置文件
with open(file_name, 'wb') as f:
    pickle.dump(action_caiji_each, f)


def save_mode_return_action():
    '''

    :return:     返回的值中，第一个是dryfan，另外一个是cduValve1
    '''
    if os.path.exists(file_name):
        with open(file_name, 'rb') as f:
            action_caiji_file = pickle.load(f)

        output_action = action_caiji_file.choose_action()

        with open(file_name, 'wb') as f:
            pickle.dump(action_caiji_file, f)
        print(output_action)
        return output_action


